#ifndef _SESSION_H_
#define _SESSION_H_

#include "object.h"
#include "common_define.h"
//#include "clock.h"
//#include "performance.h"
#include "common_singleton.h"
//#include "timer.h"
#include <string>
#include "jsonmessage.h"

namespace common
{

	class CSession;
	class CTimerItem;

	//typedef int SessionParameList[ 5 ];
	class SessionParameList
	{
	private:
		int 	parame_array[ 10 ];
		int64_t	parame_64;

	public:
		SessionParameList( )
		{
			for ( unsigned int i = 0; i < ARRAY_CNT( parame_array ); ++i )
			{
				parame_array[ i ] = 0;
			}

			parame_64 = 0;
		}

		int& operator[ ] ( int i )
		{
			return parame_array[ i ];
		}

		int64_t set_long_parame( int64_t parame )
		{
			parame_64 = parame;
			return parame_64;
		}

		int64_t get_long_parame( )const { return parame_64; }
        std::string str_parm1;
        std::string str_parm2;
	};

	typedef int( *SessionProcessFun )( CSession& db_session, bool time_out, const CJsonMessageBase* response );

	class CSession : public CObj//, public CTimer
	{
	public:
		SessionParameList	mParame;
		OBJ_ID_TYPE			mOwnerObjID;
		OBJ_ID_TYPE			mDBSessionTimer;
		bool				mSessionDelete;

		bool				is_clock_;
		//Clock				session_clock_;

		SessionProcessFun	session_fun_;
	public:
		CSession( ) { clear( ); }

		int clear( );

		int Create( SessionProcessFun session_fun, SessionParameList parame, OBJ_ID_TYPE owner_obj_id, int64_t time_out );

		virtual int Initialize( ) { return clear( ); }
		virtual int Resume( ) { return clear( ); }

		virtual void TimerActive( );
	};


	class CSessionProcess : public ::common::CSingleton< CSessionProcess >
	{
	public:
		CSessionProcess( );

		OBJ_ID_TYPE AddSession( OBJ_ID_TYPE owner_obj_id, SessionProcessFun session_fun, SessionParameList parame, int time_out = 30000 );

		void SessionProcess( OBJ_ID_TYPE session_obj_id, const CJsonMessageBase* response );


		CSession* CreateSessionObject( );
		int DestroySessionObject( OBJ_ID_TYPE session_id );
		CSession* GetSession( OBJ_ID_TYPE obj_id );

	public:
		//	static void SessionTimeOut( CTimerItem& time_item );
	};

#define server_session				CSessionProcess::GetInstance( )
#define server_session_register		server_session.RegisteSessionProcessFun

};	// namspace common

#endif // _GAMEDB_SESSION_H_


